package com.ycp.erp.printer.ui.binder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.warehouse.model.bean.Warehouse;
import com.ycp.erp.warehouse.ui.inter.WarehouseListener;

import androidx.annotation.NonNull;

/**
 * Class Des:
 * Created by bjh on 2021/8/24.
 */
public class PrinterBinder extends BaseItemBinder<Warehouse> {
    //type=1 表示选择打印机 2 表示打印机管理
    private int type;

    public PrinterBinder() {
        super(R.layout.item_printer_manager);
    }
    public void setType(int type){
        this.type=type;
    }
    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, Warehouse item) {
        ImageView ivSelect = holder.getView(R.id.ivSelect);
        View rlItem = holder.getView(R.id.rlItem);
        TextView tvDetail = holder.getView(R.id.tvDetail);
        ImageView ivArrow = holder.getView(R.id.ivArrow);
        if (type==1){
            ivSelect.setVisibility(View.VISIBLE);
            ivArrow.setVisibility(View.VISIBLE);
            tvDetail.setVisibility(View.GONE);
        }else {
            ivSelect.setVisibility(View.GONE);
            ivArrow.setVisibility(View.GONE);
            tvDetail.setVisibility(View.VISIBLE);
        }
        if (item.isSelect()) {
            ivSelect.setImageResource(R.mipmap.ic_selected_circle);
        } else {
            ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
        }
        rlItem.setOnClickListener(v -> {
            if (type==1){
                item.setSelect(!item.isSelect());
                if (item.isSelect()) {
                    if (this.warehouseListener!=null){
                        this.warehouseListener.onSelect(item);
                    }
                    ivSelect.setImageResource(R.mipmap.ic_selected_circle);
                } else {
                    ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
                }
            }else {
                RouterManager.getInstance().go(RouterPath.PRINTER_DETAIL);
            }

        });
        holder.setText(R.id.tvName,"打印机 "+getPosition(holder));
    }
    WarehouseListener warehouseListener;
    public void  setWarehouseListener(WarehouseListener warehouseListener){
        this.warehouseListener=warehouseListener;
    }
}
